package com.chainyoung.common.http.websocket;

import android.content.Context;

import com.chainyoung.common.constant.LibConstant;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

public class WebSoketUtils {

    private static WsManager wsManager;
    private static Context mContext;

    public static void init(Context context) {
        mContext = context;
    }

    private static OkHttpClient getOkHttpClient() {
        OkHttpClient client = new OkHttpClient().newBuilder()
                //.pingInterval(10, TimeUnit.SECONDS)
                .retryOnConnectionFailure(true)
                .build();
        return client;
    }

    public static WsManager getWsManager() {
        if (wsManager == null) {
            wsManager = new WsManager.Builder(mContext)
                    .wsUrl(LibConstant.WS_URL)
                    .needReconnect(true)
                    .client(getOkHttpClient())
                    .build();
        }
        return wsManager;
    }

    public static void setWsManagerNull() {
        wsManager = null;
    }


}
